package com.example.bbook.util;

public class Response {
    private Integer code;
    private String message;
    private Object data;

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    private void setResultCode(ResponseCodeEnum resultCode) {
        this.code = resultCode.code();
        this.message = resultCode.message();
    }


    public Response() {
    }

    public static Response successful() {
        Response result = new Response();
        result.setResultCode(ResponseCodeEnum.SUCCESS);
        return result;
    }

    public static Response successful(Object data) {
        Response result = new Response();
        result.setResultCode(ResponseCodeEnum.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Response fail() {
        Response result = new Response();
        result.setResultCode(ResponseCodeEnum.FAIL);
        return result;
    }

    public static Response fail(ResponseCodeEnum resultCode) {
        Response result = new Response();
        result.setResultCode(resultCode);
        return result;
    }

    public static Response fail(String message) {
        Response result = new Response();
        result.setCode(ResponseCodeEnum.FAIL.code());
        result.setMessage(message);
        return result;
    }

    public static Response fail(Integer code, String message) {
        Response result = new Response();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Response noAuth() {
        Response result = new Response();
        result.setResultCode(ResponseCodeEnum.TOKEN_INVALID);
        return result;
    }
}
